//
//  MyHeaderView.m
//  CCSD
//
//  Created by hwd on 17/9/19.
//  Copyright © 2017年 张露杰. All rights reserved.
//

#import "MyHeaderView.h"
#import "HBHMainIcon.h"
@interface MyHeaderView()
@property (nonatomic,strong)UIImageView *headerImageV;
@property (nonatomic,strong)UILabel *nameLab;//名字
@property (nonatomic,strong)UILabel *roleLab;//角色
@end
@implementation MyHeaderView

-(void)CreatUI
{
    self.backgroundColor = mainColor;
    if (!_headerImageV) {
        
        _backmageV = [[UIImageView alloc]initWithFrame:self.frame];
        _backmageV.userInteractionEnabled = YES;
        _backmageV.image = [UIImage imageNamed:@"mydi"];
        [self addSubview:_backmageV];
        
        
        //信息按钮
        _messageBtn = [TomamaUI createButton:0 Frame:CGRectZero targ:self sel:@selector(onTapLeft) titleColor:nil font:nil title:nil image:@"notice" backGroundImage:nil];
        [_messageBtn setImageEdgeInsets:UIEdgeInsetsMake(10*screenW_6, 10*screenW_6, 5*screenW_6, 21*screenW_6)];
        [_backmageV addSubview:_messageBtn];
        [_messageBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(@(10*screenW_6));
            make.width.equalTo(@(60*screenW_6));
            make.height.equalTo(@(40*screenW_6));
            make.bottom.equalTo(_backmageV.mas_bottom).offset(-143*screenW_6);
        }];

        
        //设置按钮
        _shezhiBtn = [TomamaUI createButton:0 Frame:CGRectZero targ:self sel:@selector(onTapRight) titleColor:nil font:nil title:nil image:@"set" backGroundImage:nil];
        [_shezhiBtn setImageEdgeInsets:UIEdgeInsetsMake(5*screenW_6, 5*screenW_6, 5*screenW_6, 5*screenW_6)];
        [_backmageV addSubview:_shezhiBtn];
        [_shezhiBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(@(-10*screenW_6));
            make.width.equalTo(@(40*screenW_6));
            make.height.equalTo(@(50*screenW_6));
            make.bottom.equalTo(_backmageV.mas_bottom).offset(-135*screenW_6);
        }];
   
        
        //头像
        _headerImageV = [TomamaUI createImageView:CGRectZero backGroundImageV:@"forumHeader"];
        _headerImageV.contentMode=UIViewContentModeScaleAspectFill;
        _headerImageV.clipsToBounds=YES;
        [_headerImageV.layer setCornerRadius:34*screenW_6];
        _headerImageV.layer.masksToBounds = YES;
        _headerImageV.userInteractionEnabled = YES;
        [_backmageV addSubview:_headerImageV];
        [_headerImageV mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(@(SCREENW/2-34*screenW_6));
            make.right.equalTo(@(-(SCREENW/2-34*screenW_6)));
            make.height.equalTo(@(68*screenW_6));
        }];
        [_headerImageV addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(changeHead)]];
        
        //名字
        _nameLab = [TomamaUI createLabel:CGRectZero textAligment:1 font:[UIFont systemFontOfSize:16*screenW_6] textColor:[UIColor whiteColor] text:[Storage getName]];
        [_backmageV addSubview:_nameLab];
        [_nameLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_headerImageV.mas_bottom).offset(15*screenW_6);
            make.left.equalTo(@0);
            make.right.equalTo(@0);
            make.height.equalTo(@(25*screenW_6));
            make.bottom.equalTo(_backmageV.mas_bottom).offset(-35*screenW_6);
        }];
        
    }
}
-(void)onTapLeft//信息按钮
{
    if (_headerBlock) {
        self.headerBlock(10);
    }
}
-(void)onTapRight//设置按钮
{
    if (_headerBlock) {
        self.headerBlock(11);
    }
}
-(void)setDataDic:(NSDictionary *)dataDic
{
    //头像
    [_headerImageV sd_setImageWithURL:[NSURL URLWithString:[Storage getUserPhoto]] placeholderImage:[UIImage imageNamed:@"forumHeader"]];
    //名字
    _nameLab.text = [Storage getName];
    //角色
//    if ([ToolViewVC isNotNullStr:[Storage getUserType]]) {
//        _roleLab.text = ([[Storage getUserType] intValue]<=5)?RolesArr[[[Storage getUserType] intValue]-1]:@"";
//    }
}
/*********************************************/
//三个按钮 我的帖子 关注 粉丝
-(void)addThreeBtn
{
    self.backgroundColor = [UIColor whiteColor];
    
    NSArray *titleArr = @[@{@"name":@"我的帖子",@"image":@"tiezi_icon"},@{@"name":@"关注",@"image":@"guanzhu_icon"},@{@"name":@"粉丝",@"image":@"fensi_icon"}];
    for (int i = 0; i < titleArr.count; i++) {
//        HBHMainIcon *icon = [[HBHMainIcon alloc]initWithFrame:CGRectMake(SCREENW/3*i,10*screenW_6,SCREENW/3-2,80*screenW_6) data:titleArr[i] index:i HangNumber:3  Height:12*screenW_6 complete:^(NSInteger index) {
//            NSLog(@"click on %ld",index);
//            if (_headerBlock) {
//                self.headerBlock(index);
//            }
//        }];
//        [self addSubview:icon];
        
        UIView *view = [[UIView alloc]initWithFrame:CGRectMake(i*SCREENW/3, 0, SCREENW/3, 80*screenW_6)];
        [self addSubview:view];
        
        UIImageView *icon = [TomamaUI createImageView:CGRectMake(0, 16*screenW_6, 40*screenW_6, 27.5*screenW_6) backGroundImageV:titleArr[i][@"image"]];
        [view addSubview:icon];
        icon.center = CGPointMake(view.frame.size.width/2, icon.center.y);
        
        UILabel *label = [TomamaUI createLabel:CGRectMake(0, CGRectGetMaxY(icon.frame) + 11*screenW_6, SCREENW/3, 13*screenW_6) textAligment:1 font:[UIFont systemFontOfSize:13*screenW_6] textColor:TextBlack text:titleArr[i][@"name"]];
        [view addSubview:label];
        view.tag = i;
        [view addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(click:)]];
        
        if (i != 2) {
            [self addSubview:[ToolViewVC addCellLineLab:CGRectMake(SCREENW/3*(i+1)-1, 20*screenW_6, 1, 40*screenW_6)]];
        }
    }
}

-(void)click:(UITapGestureRecognizer *)tap
{
    if (_headerBlock) {
        self.headerBlock(tap.view.tag);
    }
}

-(void)changeHead
{
    if (_changeHeaderBlock) {
        _changeHeaderBlock();
    }
}

@end
